#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define ISLESS(a, b) if ((a) != (b)) return (a) < (b)
#define ISGREATER(a, b) if ((a) != (b)) return (a) > (b)

vector <int> m_bookHeights;
vector <int> m_bookWidths;
vector <int> m_bookValues;

bool orderLess(int a, int b)
{
    ISGREATER(m_bookValues[a], m_bookValues[b]);
    ISLESS(m_bookHeights[a], m_bookHeights[b]);
    ISLESS(m_bookWidths[a], m_bookWidths[b]);
    return false;
}

class BookSelection
{
public:
    vector <int> arrange(int H, int W, vector <int> bookHeights, vector <int> bookWidths, vector <int> bookValues)
    {
        m_bookHeights = bookHeights;
        m_bookWidths = bookWidths;
        m_bookValues = bookValues;

        int n = bookHeights.size();
        vector<int> order(n);
        for (int i = 0; i < n; ++i) order[i] = i;

        sort(order.begin(), order.end(), orderLess);

        int shelves = 1;
        int totalH = 10;
        int curMaxH = 0;
        int curW = 0;
        vector<int> result(n, -1);
        for (int t = 0; t < n; ++t)
        {
            int i = order[t];
            if (totalH + bookHeights[i] <= H)
            {
                if (curW + bookWidths[i] <= W)
                {
                    result[i] = shelves - 1;
                    curMaxH = max(curMaxH, bookHeights[i]);
                    curW += bookWidths[i];
                }
                else
                {
                    if (totalH + curMaxH + 10 <= H)
                    {
                        totalH = totalH + curMaxH + 10;
                        curW = 0;
                        curMaxH = 0;
                        ++shelves;
                        --t;
                    }
                }
            }
        }
    
        //cerr << "curW = " << curW << endl;
        cerr << "totalH = " << totalH + curMaxH << endl;
        return result;
    }
};

int nextInt()
{
    int n;
    cin >> n;
    return n;
}

void println(int n)
{
    cout << n << endl;
}

int main()
{
	int H = nextInt();
    int W = nextInt();
    int X = nextInt();
	vector<int> bookHeights(X);
    for(int i = 0; i<X; i++)
      bookHeights[i] = nextInt();
	vector<int> bookWidths(X);
    for(int i = 0; i<X; i++)
      bookWidths[i] = nextInt();
	vector<int> bookValues(X);
    for(int i = 0; i<X; i++)
      bookValues[i] = nextInt();
	BookSelection bs;
    vector<int> ret = bs.arrange(H, W, bookHeights, bookWidths, bookValues);
    for(int i = 0; i<X; i++)
      println(ret[i]);
	return 0;
}
